const deffaultName="张三李四"/*少于等于5个字*/

var app=getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    userInfo:{
      loginState:false,
      avatarUrl:"",
      userName:"",
      permission:0,
      motto:""
    },
    list:[
      {
        title:"登录/注册",
        iconURL:"/static/image/icon/个人信息 .png",
        bindtap:"information"
      },
    ],
    role:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },

  information(){
    if(this.data.userInfo.loginState){
      wx.navigateTo({
        url:'/pages/information/information'
      })
    }
    else{
      wx.navigateTo({
        url:'/pages/registerAndLogin/registerAndLogin'
      })
    }
  },


  aboutUs(){
    wx.navigateTo({
      url: '/pages/aboutUs/aboutUs',
    })
  },

  more(){
    wx.navigateTo({
      url: '/pages/more/more',
    })
  },

  manage(){
    wx.navigateTo({
      url: '/pages/manage/manage',
    })
  },

  push(){
    wx.navigateTo({
      url: '/pages/push/push',
    })
  },

  commentDetail(){
    wx.navigateTo({
      url: '/pages/commentDetail/commentDetail',
    })
  },

  goAdvice(){
    wx.navigateTo({
      url: '/pages/advice/advice',
    })
  },

  logout(){
    wx.showModal({
      title: '再次确认',
      content: '是否退出登录',
      complete: (res) => {
        if (res.cancel) {
          
        }
    
        if (res.confirm) {
          wx.setStorageSync('token', "")
          this.setData({
            userInfo:{
              loginState:false,
              avatarUrl:"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0",
              userName:"",
              permission:0,
              motto:""
            },
            list:[
              {
                title:"登录/注册",
                iconURL:"/static/image/icon/个人信息 .png",
                bindtap:"information"
              },
            ]
          })
          app.globalData.userInfo.loginState=false;
          app.globalData.userInfo.avatarUrl="https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0";
          app.globalData.userInfo.userName="默认昵称";
          app.globalData.userInfo.permission=0;

        }
      }
    })

    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow(){
    this.setData({
      userInfo:app.globalData.userInfo,
      role:app.globalData.role
    });
    if (app.globalData.userInfo.loginState) {
      this.setData({
        list:[
          {
            title:"个人信息",
            iconURL:"/static/image/icon/个人信息 .png",
            bindtap:"information"
          },
          {
            title:"评论",
            iconURL:"/static/image/icon/评论.png",
            bindtap:"commentDetail"
          },
          {
            title:"建议或投诉",
            iconURL:"/static/image/icon/advice.png",
            bindtap:"goAdvice"
          },
        ]
      });
      if(app.globalData.userInfo.permission>1){
        var newList=this.data.list.concat(
          {
            title:"管理端",
            iconURL:"/static/image/icon/管理.png",
            bindtap:"manage"
          }
        )
        this.setData({
          list:newList
        })
      };
      if(app.globalData.userInfo.permission==2){
        var newList=this.data.list.concat(
          {
            title:"推送",
            iconURL:"/static/image/icon/轮播图管理.png",
            bindtap:"push"
          }
        )
        this.setData({
          list:newList
        })
      };
      if(wx.getStorageSync('token')!=""){
        var newList=this.data.list.concat({
          title:"退出登录",
          iconURL:"/static/image/icon/退出.png",
          bindtap:"logout"
        })
        this.setData({
          list:newList
        })
      };
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})